Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
tap-parser
Advanced tools
The tap-parser npm package is a TAP (Test Anything Protocol) parser for Node.js. It allows you to parse TAP output, which is a standard format for test results, and provides a way to handle the parsed data programmatically.
Parsing TAP output
This feature allows you to parse TAP output and handle assertions and results. The code sample demonstrates how to create a parser instance, listen for 'assert' and 'complete' events, and parse a simple TAP string.
const Parser = require('tap-parser');
const parser = new Parser();
parser.on('assert', assert => {
console.log('assertion:', assert);
});
parser.on('complete', results => {
console.log('results:', results);
});
parser.end('TAP version 13
ok 1 - this is fine
not ok 2 - this is not fine
1..2
');
Handling TAP comments
This feature allows you to handle comments in TAP output. The code sample demonstrates how to listen for 'comment' events and parse a TAP string that includes a comment.
const Parser = require('tap-parser');
const parser = new Parser();
parser.on('comment', comment => {
console.log('comment:', comment);
});
parser.end('TAP version 13
# this is a comment
ok 1 - this is fine
');
Handling TAP plan
This feature allows you to handle the TAP plan, which specifies the number of tests expected. The code sample demonstrates how to listen for 'plan' events and parse a TAP string that includes a plan.
const Parser = require('tap-parser');
const parser = new Parser();
parser.on('plan', plan => {
console.log('plan:', plan);
});
parser.end('TAP version 13
1..2
ok 1 - this is fine
ok 2 - this is also fine
');
The 'tap' package is a comprehensive TAP producer and consumer for Node.js. It includes a test runner, assertion library, and TAP parser. Compared to tap-parser, 'tap' offers a more complete testing framework but is heavier and more feature-rich.
The 'tap-out' package is another TAP parser that focuses on providing a simple interface for parsing TAP output. It is similar to tap-parser but offers a different API and may be preferred for its simplicity and ease of use.
The 'tap-consumer' package is designed to consume TAP output and provide a structured representation of the test results. It is similar to tap-parser but focuses more on consuming and structuring the data rather than just parsing it.
parse the test anything protocol
var parser = require('tap-parser');
var p = parser(function (results) {
console.dir(results);
});
process.stdin.pipe(p);
given some TAP-formatted input:
$ node test.js
TAP version 13
# beep
ok 1 should be equal
ok 2 should be equivalent
# boop
ok 3 should be equal
ok 4 (unnamed assert)
1..4
# tests 4
# pass 4
# ok
parse the output:
$ node test.js | node parse.js
{ ok: true,
asserts:
[ { ok: true, number: 1, name: 'should be equal' },
{ ok: true, number: 2, name: 'should be equivalent' },
{ ok: true, number: 3, name: 'should be equal' },
{ ok: true, number: 4, name: '(unnamed assert)' } ],
pass:
[ { ok: true, number: 1, name: 'should be equal' },
{ ok: true, number: 2, name: 'should be equivalent' },
{ ok: true, number: 3, name: 'should be equal' },
{ ok: true, number: 4, name: '(unnamed assert)' } ],
fail: [],
todo: [],
errors: [],
plan: { start: 1, end: 4 } }
This package also has a tap-parser
command.
usage: tap-parser OPTIONS
Parse TAP from INPUT. If there are any failures, exits with
a non-zero status code.
OPTIONS are:
-i, --input Read from INPUT. Default: stdin.
-o, --output Write to OUTPUT. Default: stdout.
-r, --results Print results as json. Otherwise pass INPUT
through to OUTPUT.
-h, --help Show this help message.
-v, --version Print the current version of tap-parser.
var parser = require('tap-parser')
Return a writable stream p
that emits parse events.
If cb
is given it will listen for the 'results'
event.
results.errors
is an array containing any parse errors, such as out of order
assertions or missing plans.
Every /^(not )?ok\b/
line will emit an 'assert'
event.
Every assert
object has these keys:
assert.ok
- true if the assertion succeeded, false if failedassert.number
- the assertion numberassert.name
- optional short description of the assertionand may also have
assert.todo
- optional description of why the assertion failure is
not a problem.When results
are returned, each assert
object will have been
appended to the list asserts
and one of (pass
, fail
, todo
).
Every /^# (.+)/
line will emit the string contents of comment
.
Every /^\d+\.\.\d+/
line emits a 'plan'
event for the test numbers
plan.start
through plan.end
, inclusive.
If the test is completely skipped the result will look like
{ ok: true,
asserts: [],
pass: [],
fail: [],
errors: [],
plan:
{ start: 1,
end: 0,
skip_all: true,
skip_reason: 'This code has no seat belt' } }
A /^TAP version (\d+)/
line emits a 'version'
event with a version number or
string.
All other lines will trigger an 'extra'
event with the line text.
With npm do:
npm install tap-parser
You can use browserify to require('tap-parser')
in
the browser.
MIT
FAQs
parse the test anything protocol
We found that tap-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.